import React from 'react';
import PropTypes from 'prop-types';
import routes from './routes';
import cloneDeep from 'lodash/cloneDeep';
import {getDetail} from './api';
import {Button, Form, Row, Col, Card, Spin, Table, Popconfirm, message as msg} from 'antd';
import {FORM_OPTIONS, DATE_FORMAT, FORM_ROW_OPTIONS, TABLE, FIXED_COLUMN_WIDTH, DATETIME_FORMAT} from '../constants';
import Return from '../common/Return';
import FormItem from 'antd/lib/form/FormItem';
import {uuid, hasPermissions} from './utils';
import {conventEnumValueToString, formatAmount, formatDateTime} from '../utils';
import {PERMISSION} from './constants';
import {newOrUpdateOrderValidator} from './validator';
import {injectIntl, language, formatMessage} from './intl';
import WrappedSelect from '../common/WrappedSelect';
import SearchInput from 'Shared/components/SearchInput';
import TextInput from 'Shared/components/TextInput';
import styles from './style.css';
import AthTypeList from './AthTypeList';
import VinSelectPanel from './VinSelectPanel';
import WrappedInputNumber from '../common/WrappedInputNumber';
import FaultItemSelectPanel from '../common/FaultItemSelect/SelectEdit';
import {currency, goodWillDetailType, fileType} from '../Enum';
let totalFee = 0;
let laborFee = 0;
let materialFee = 0;
export class NewPanel extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        validate: false,
        showVinSelectPanel: false,
        data: {},
        details: [],
        athDetails: [],
        approveResults: []
    };

    componentDidMount() {
        if(this.props.id)
            this.getDetailInfo();
    }
    
    componentWillUnmount() {
        this.isunmount = true;
    }

    getDetailInfo = () => {
        this.setState({loading: true});
        getDetail(this.props.id)
            .then(res => {
                if(res.ok)
                    this.setState({
                        loading: false,
                        data: res.data,
                        details: res.data.details,
                        athDetails: res.data.athDetails,
                        approveResults: res.data.approveResults,
                    });
                this.setState({
                    loading: false
                });
            });
    }

    handleFilterChange = (value, name) => {
        const data = Object.assign({}, this.state.data, {
            [name]: value
        });
        this.setState({
            data,
            hasOperat: true
        });
    }

    onClickReturnBtn = () => {
        this.props.onCancel();
    }
    onSelectDealer = (condition = {}) => {
        this.setState(state => {
            const newData = cloneDeep(state.data);
            return {
                hasOperat: true,
                data: {
                    ...newData,
                    dealerId: condition.id,
                    dealerCode: condition.code,
                    dealerName: condition.name,
                }
            };
        });
    };
    onSubmit = value => {
        const isValid = newOrUpdateOrderValidator(this.state.data, this.state.details);
        const data = this.state.data;
        if(!isValid) {
            this.setState({
                validate: true
            });
            return;
        }
        this.setState({
            loading: true,
        });
        data.totalFee = totalFee;
        data.laborFee = laborFee;
        data.materialFee = materialFee;
        if(value === 'save')
            this.props.onSubmit(Object.assign({}, data, {
                currency: this.props.currency,
                createTime: new Date(),
                country: this.props.country,
                saveStatus: true,
            }), this.state.details, this.state.athDetails || []).then(() => {
                if(this.success)
                    this.props.successReturn();
                if(!this.isunmount)
                    this.setState({loading: false});
            });
        if(value === 'saveAndSubmit')
            this.props.onSubmit(Object.assign({}, data, {
                currency: this.props.currency,
                createTime: new Date(),
                country: this.props.country,
                saveStatus: false,
            }), this.state.details, this.state.athDetails || []).then(() => {
                if(this.success)
                    this.props.successReturn();
                if(!this.isunmount)
                    this.setState({loading: false});
            });
    }
    onClickSearchVinBtn = () => {
        this.setState({
            showVinSelectPanel: true
        });
    }
    onClickStopPropagation = e => {
        e.stopPropagation();
    }
    onSelectVin = records => {
        if(records.shipDate)
            this.setState({
                data: Object.assign({}, this.state.data, {
                    vinId: records.id,
                    vin: records.vin,
                    productCategoryCode: records.productCategoryCode,
                    engineCode: records.engineCode,
                    salesDate: records.salesDate,
                    transmissionSn: records.transmissionSn,
                }),
                hasOperat: true,
                showVinSelectPanel: false
            });
        else return msg.warn(formatMessage({
            id: 'newPanel.validate.onSelectVin',
            defaultMessage: `VIN为${records.vin}的车辆缺少发车日期，请联系相关人员确认`
        }));
    }
    onCloseVinSelectPanel = () => {
        this.setState({showVinSelectPanel: false});
    }
    onDeleteAll = () => {
        this.setState({
            details: [],
            hasOperat: true
        });
    }
    onDeleteDetail = e => {
        const id = e.target.dataset.id;
        const tmp = this.state.details.filter(d => d.id !== id);
        this.setState({
            details: [...tmp],
            hasOperat: true
        });
    }
    onTableChange = (value, name, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    [name]: value,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onClickAddDetailBtn = () => {
        const details = this.state.details;
        this.setState({
            details: [
                ...details,
                {
                    id: uuid(),
                }
            ],
            hasOperat: true
        });
    };
    onRemovePhoto = data => {
        const athDetails = this.state.athDetails || [];
        let attachments = [];
        const tmp = athDetails.map(d => {
            if(d.fileType === fileType.图片) {
                attachments = d.attachments || [];
                attachments.splice({
                    fileId: data.id,
                    fileName: data.name
                }, 1);
                return Object.assign({}, d, {
                    attachments: [...attachments]
                });
            }
            return d;
        });
        this.setState({
            athDetails: tmp,
            hasOperat: true
        });
    }
    onRemoveFile = data => {
        const athDetails = this.state.athDetails || [];
        let attachments = [];
        const tmp = athDetails.map(d => {
            if(d.fileType === fileType.文件) {
                attachments = d.attachments || [];
                attachments.splice({
                    fileId: data.id,
                    fileName: data.name
                }, 1);
                return Object.assign({}, d, {
                    attachments: [...attachments]
                });
            }
            return d;
        });
        this.setState({
            athDetails: tmp,
            hasOperat: true
        });
    }
    onChangeUploadFile = data => {
        const athDetails = this.state.athDetails || [];
        const index = athDetails.findIndex(v => v.fileType === fileType.文件);
        const attachmentsTmp = [];
        attachmentsTmp.push({
            fileId: data.id,
            fileName: data.fileName
        });
        if(index === -1) {
            athDetails.push({
                fileType: fileType.文件,
                attachments: attachmentsTmp
            });
            this.setState({
                athDetails: [...athDetails],
                hasOperat: true
            });
        } else {
            const tmp = athDetails.map(d => {
                if(d.fileType === fileType.文件)
                    return Object.assign({}, d, {
                        attachments: d.attachments.concat(attachmentsTmp)
                    });
                return d;
            });
            this.setState({
                athDetails: tmp,
                hasOperat: true
            });
        }
    }
    onChangeUploadPhoto = data => {
        const athDetails = this.state.athDetails || [];
        const index = athDetails.findIndex(v => v.fileType === fileType.图片);
        const attachmentsTmp = [];
        attachmentsTmp.push({
            fileId: data.id,
            fileName: data.fileName
        });
        if(index === -1) {
            athDetails.push({
                fileType: fileType.图片,
                attachments: attachmentsTmp
            });
            this.setState({
                athDetails: [...athDetails],
                hasOperat: true
            });
        } else {
            const tmp = athDetails.map(d => {
                if(d.fileType === fileType.图片)
                    return Object.assign({}, d, {
                        attachments: d.attachments.concat(attachmentsTmp)
                    });
                return d;
            });
            this.setState({
                athDetails: tmp,
                hasOperat: true
            });
        }
    }
    onSelectFaultItem = data => {
        this.setState({
            data: Object.assign({}, this.state.data, {
                faultItemId: data.id,
                faultItemCode: data.code,
                faultItemName: `${data.categoryL1Name}-${data.categoryL2Name}-${data.name}`,
            }),
            hasOperat: true
        });
    }
    render() {
        const {data, details, athDetails, validate,
            loading, showVinSelectPanel, hasOperat} = this.state;
        const {pagePermission, id, brands, country} = this.props;
        const validateCurrency = !data.currency && validate ? 'error' : null;
        const validateVin = !data.vin && validate ? 'error' : null;
        const validateProductCategoryCode = !data.productCategoryCode && validate ? 'error' : null;
        const validateEngineCode = !data.engineCode && validate ? 'error' : null;
        const validateMileage = !data.mileage && validate ? 'error' : null;
        const validateTel = !data.tel && validate ? 'error' : null;
        const validateFaultItem = !data.faultItem && validate ? 'error' : null;
        const validateCustomer = !data.customer && validate ? 'error' : null;
        const validateCountry = !data.country && validate ? 'error' : null;
        const validateBrand = !data.brandId && validate ? 'error' : null;
        const submitable = hasPermissions(PERMISSION.add, pagePermission);
        const faultItemInfo = data.faultItemId ? {
            id: data.faultItemId,
            code: data.faultItemCode,
            name: data.faultItemName,
        } : null;
        totalFee = 0;
        laborFee = 0;
        materialFee = 0;
        if(details)
            details.forEach(d => {
                if(d.type === 1)
                    laborFee += (d.price * d.usedQty || 0);
                
                if(d.type === 2)
                    materialFee += (d.price * d.usedQty || 0);
            });
        
        totalFee = laborFee + materialFee;
        const colums = [{
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'newPanel.column.type',
                defaultMessage: '类型'
            })}</span>,
            dataIndex: 'type',
            width: 300,
            render: (text, record) => {
                const validates = (!text) && validate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validates}>
                        <WrappedSelect
                            name="type"
                            value={record.type}
                            options={goodWillDetailType.toList(language)}
                            onChange={value => this.onTableChange(value, 'type', record.id)} />
                    </FormItem>
                );
            }
        },
        {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'newPanel.column.code',
                defaultMessage: '编号'
            })}</span>,
            dataIndex: 'code',
            render: (text, record) => {
                const validates = (!text) && validate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validates}>
                        <TextInput
                            name="code"
                            value={record.code}
                            onChange={value => this.onTableChange(value, 'code', record.id)} />
                    </FormItem>);
            }
        },
        {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'newPanel.column.name',
                defaultMessage: '名称'
            })}</span>,
            dataIndex: 'name',
            render: (text, record) => {
                const validates = (!text) && validate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validates}>
                        <TextInput
                            name="name"
                            value={record.name}
                            onChange={value => this.onTableChange(value, 'name', record.id)} />
                    </FormItem>);
            }
        },
        {
            title: <span className="ant-form-item-required">{ formatMessage({
                id: 'newPanel.column.usedQty',
                defaultMessage: '数量'
            })}</span>,
            dataIndex: 'usedQty',
            render: (text, record) => {
                const validates = (!text) && validate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validates}>
                        <WrappedInputNumber
                            name="usedQty"
                            min={0}
                            precision={0}
                            value={record.usedQty}
                            onChange={value => this.onTableChange(value, 'usedQty', record.id)} />
                    </FormItem>
                );
            }
        },
        {
            title: <span className="ant-form-item-required">{ formatMessage({
                id: 'newPanel.column.price',
                defaultMessage: '单价'
            })}</span>,
            dataIndex: 'price',
            render: (text, record) => {
                const validates = (!text) && validate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validates}>
                        <WrappedInputNumber
                            name="price"
                            min={0}
                            precision={2}
                            value={record.price}
                            onChange={value => this.onTableChange(value, 'price', record.id)} />
                    </FormItem>
                );
            }
        },
        {
            title: <span className="ant-form-item-required">{ formatMessage({
                id: 'newPanel.column.totalPrice',
                defaultMessage: '费用合计'
            })}</span>,
            dataIndex: 'totalPrice',
            render: (text, record) => formatAmount(record.price * record.usedQty || 0)
        },
        {
            title: details && details.length > 0
                ? (
                    <Popconfirm placement="topRight" title={formatMessage({
                        id: 'newPanel.column.allDelete',
                        defaultMessage: '是否确认全部删除？'
                    })} onConfirm={this.onDeleteAll} >
                        <a>{formatMessage({
                            id: 'newPanel.column.empty',
                            defaultMessage: '清空'
                        })}</a>
                    </Popconfirm>
                )
                : <a>{formatMessage({
                    id: 'newPanel.column.empty',
                    defaultMessage: '清空'
                })}</a>,
            dataIndex: 'productCategoryId',
            fixed: 'right',
            width: FIXED_COLUMN_WIDTH,
            render: (text, record) => <a data-id={record.id} onClick={this.onDeleteDetail}>{formatMessage({
                id: 'newPanel.column.delete',
                defaultMessage: '删除'
            })}</a>
        }];
        return (
            <div className="form-standard">
                <Spin spinning={loading}>
                    <Form>
                        <Card {...FORM_OPTIONS.col} title={formatMessage({
                            id: 'newPanel.card.title',
                            defaultMessage: '基本信息'
                        })}>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.text.code',
                                        defaultMessage: '编号'
                                    })}{...FORM_OPTIONS.item} required>
                                        {
                                            id ? data.code : <span className="value-font">{formatMessage({
                                                id: 'newPanel.value.defalut',
                                                defaultMessage: '尚未生成'
                                            })}</span>
                                        }
                                        
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.brand',
                                            defaultMessage: '品牌'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateBrand} required >
                                        {
                                            id ? `(${data.brandCode})${data.brandName}` : <WrappedSelect
                                                allowClear
                                                name="brandId"
                                                value={data.brandId}
                                                options={brands}
                                                onChange={this.handleFilterChange}/>
                                        }
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.currency',
                                            defaultMessage: '币种'
                                        })} {...FORM_OPTIONS.item} validateStatus={validateCurrency} required>
                                        {conventEnumValueToString(currency, currency)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.form.country',
                                        defaultMessage: '国家'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={validateCountry}
                                    required>
                                        {country}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.VIN',
                                        defaultMessage: 'VIN'
                                    })}{...FORM_OPTIONS.item} validateStatus={validateVin} required>
                                        <SearchInput
                                            disabled={true}
                                            value={data.vin}
                                            onClickSearchBtn={() => this.onClickSearchVinBtn()} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.productCategoryCode',
                                            defaultMessage: '车型'
                                        })} {...FORM_OPTIONS.item} validateStatus={validateProductCategoryCode} required>
                                        {data.productCategoryCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.engineCode',
                                            defaultMessage: '发动机号'
                                        })} {...FORM_OPTIONS.item} validateStatus={validateEngineCode} required>
                                        {data.engineCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.transmissionSn',
                                            defaultMessage: '变速箱号'
                                        })} {...FORM_OPTIONS.item}>
                                        {data.transmissionSn}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.salesDate',
                                            defaultMessage: '实销日期'
                                        })} {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.salesDate, DATE_FORMAT)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'queryPanel.form.mileage',
                                            defaultMessage: '行驶里程'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateMileage} required>
                                        <WrappedInputNumber
                                            min={0}
                                            precision={0}
                                            name="mileage"
                                            value={data.mileage}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.text.tel',
                                        defaultMessage: '联系电话'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={validateTel}
                                    required>
                                        <TextInput
                                            name="tel"
                                            value={data.tel}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.faultItem',
                                            defaultMessage: '故障代码'
                                        })}
                                        {...FORM_OPTIONS.item}
                                        validateStatus={validateFaultItem}
                                        required>
                                        <div onClick={this.onClickStopPropagation}>
                                            <FaultItemSelectPanel
                                                value={faultItemInfo}
                                                onSelect={this.onSelectFaultItem} /></div>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.text.customer',
                                        defaultMessage: '客户名称'
                                    })} {...FORM_OPTIONS.item}
                                    validateStatus={validateCustomer}
                                    required>
                                        <TextInput
                                            name="customer"
                                            value={data.customer}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.totalFee',
                                            defaultMessage: '申请金额'
                                        })} {...FORM_OPTIONS.item} required>
                                        {formatAmount(totalFee)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'newPanel.form.createTime',
                                            defaultMessage: '申请时间'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {formatDateTime(new Date(), DATETIME_FORMAT)}
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row className="row-margin">
                                <Col>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.data.opinion',
                                        defaultMessage: '申请原因'
                                    })}{...FORM_ROW_OPTIONS.item}><TextInput
                                            name="opinion"
                                            type="textarea"
                                            value={data.opinion}
                                            onBlur={this.handleFilterChange}/></FormItem>
                                </Col>
                            </Row>
                            <Row className="row-margin">
                                <Col>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.data.remark',
                                        defaultMessage: '备注'
                                    })}{...FORM_ROW_OPTIONS.item}><TextInput
                                            name="remark"
                                            type="textarea"
                                            value={data.remark}
                                            onBlur={this.handleFilterChange}/></FormItem>
                                </Col>
                            </Row>
                        </Card>
                        <Card
                            title={formatMessage({
                                id: 'newPanel.operation.detail',
                                defaultMessage: 'GoodWill清单'
                            })}>
                            <Button
                                type="dashed"
                                icon="plus"
                                block
                                className={styles.plusBtn}
                                onClick={this.onClickAddDetailBtn}>
                                {formatMessage({
                                    id: 'newPanel.operation.new',
                                    defaultMessage: '新增'
                                })}
                            </Button>
                            <Table
                                className="white-space-nowrap"
                                columns={colums}
                                rowKey="id"
                                pagination={false}
                                dataSource={details}
                                {...TABLE} />
                        </Card>
                        <Card
                            title={formatMessage({
                                id: 'newPanel.operation.fileAth',
                                defaultMessage: '附件清单'
                            })}>
                            <AthTypeList
                                onRemovePhoto={this.onRemovePhoto}
                                onRemoveFile={this.onRemoveFile}
                                athDetails={athDetails}
                                onChangeUploadPhoto={this.onChangeUploadPhoto}
                                onChangeUploadFile={this.onChangeUploadFile}/>
                        </Card>
                        <Card type="inner">
                            <Row>
                                <Col disabled={!submitable} className="col-align-right">
                                    <Button key="submit" loading={loading}
                                        onClick={() => this.onSubmit('save')} type="primary">{formatMessage({
                                            id: 'newPanel.btn.submit',
                                            defaultMessage: '保存'
                                        })}</Button>
                                    <Button key="saveAndSubmit" style={{marginLeft: '10px'}} loading={loading}
                                        onClick={() => this.onSubmit('saveAndSubmit')} type="primary">{formatMessage({
                                            id: 'newPanel.btn.saveAndSubmit',
                                            defaultMessage: '保存并提交'
                                        })}</Button>
                                </Col>
                            </Row>
                        </Card>
                    </Form>
                </Spin>
                {
                    showVinSelectPanel &&
                    <VinSelectPanel
                        selectKey={data.id}
                        onCancel={this.onCloseVinSelectPanel}
                        onSelect={this.onSelectVin} />
                }
                <div className="page-toolbar">
                    <Return
                        onConfirm={this.onClickReturnBtn}
                        disabled={loading}
                        showWarning={hasOperat} />
                </div>
            </div>
        );
    }
}

NewPanel.propTypes = {
    onCancel: PropTypes.func.isRequired,
    onSubmit: PropTypes.func.isRequired,
    history: PropTypes.object,
    isDealerUser: PropTypes.bool,
    pagePermission: PropTypes.array,
};
import {connect} from 'react-redux';
import {
    onSubmit,
    tableSearch,
} from './actions';
import {selectorFactory} from 'Shared/utils/immutableToJsSelectorFactory';
import {createSelector} from 'reselect';
const getPagePermission = selectorFactory(['page', 'domainData', 'permissions', 'data']);
const getBrands = createSelector(
    state => state.getIn(['page', 'domainData', 'initData', 'brands']),
    data => {
        const brands = data.toJS();
        return brands
            ? brands.map(item => ({
                value: item.id,
                text: `(${item.code})${item.name}`,
            }))
            : [];
    }
);

const mapStateToProps = state => ({
    pagePermission: getPagePermission(state),
    brands: getBrands(state),
    isDealerUser: state.getIn((['page', 'domainData', 'initData', 'isDealerUser'])),
    country: state.getIn((['page', 'domainData', 'initData', 'country'])),
    currency: state.getIn((['page', 'domainData', 'initData', 'currency'])),
});

const mapDispatchToProps = (dispatch, props) => {
    const ownProps = {
        onSubmit: (data, details, athDetails) => dispatch(onSubmit(data, details, athDetails)).then(result => {
            if(result.success) {
                dispatch(tableSearch());
                props.history.push(routes.query.url());
            }
        }),
        onCancel: () => props.history.push(routes.query.url())
    };
    return ownProps;
};

export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(NewPanel));
